package com.ywh.composetest.widget

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.BottomSheetScaffold
import androidx.compose.material3.BottomSheetScaffoldState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.ScaffoldDefaults
import androidx.compose.material3.Text
import androidx.compose.material3.rememberBottomSheetScaffoldState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.launch


@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun CommonBottomSheet(
    showSheet: MutableState<Boolean>,
    shape: Shape = RoundedCornerShape(0.dp),
    containerColor: Color = Color.White,
    content: @Composable ColumnScope.() -> Unit
) {
    ModalBottomSheet(
        onDismissRequest = {
            showSheet.value = false
        },
        shape = shape,
        containerColor = containerColor,
        dragHandle = null,
    ) {
        content.invoke(this)
    }
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun CommonBottomSheet2(
    scaffoldState: BottomSheetScaffoldState,
    shape: Shape = RoundedCornerShape(0.dp),
    containerColor: Color = Color.White,
    content: @Composable ColumnScope.() -> Unit
) {
    BottomSheetScaffold(
        scaffoldState = scaffoldState,
        sheetContent = {
            content.invoke(this)
        },
        sheetShape = shape,
        sheetPeekHeight = 100.dp,
        sheetContainerColor = containerColor,
        containerColor = containerColor
    ) {
    }
}

@Preview
@Composable
private fun Preview() {
    CommonBottomSheet(remember {
        mutableStateOf(true)
    }) {

    }
}